package cc.owoo.godpen.reflect;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * 函数值设置
 * Created by nimensei
 * 2022-05-16 上午 10:26
 **/
public record MethodSet(Method method, TypeTranslate valueTranslate) implements ValueSet {
    @Override
    public boolean set(Object object, Object value) throws IllegalAccessException, InvocationTargetException {
        if (object == null)
            return false;
        if (value != null) {
            value = valueTranslate.parse(value, null);
            if (value == null)
                return false;
        }
        method.invoke(object, value);
        return true;
    }

    @Override
    public boolean fill(Object object, Object value) throws IllegalAccessException, InvocationTargetException {
        set(object, value);
        return true;
    }
}
